var GameData = require('../module/GameData')();
var startData = require('../module/startData')();
// var protobuf = require("protobufjs");

cc.Class({
    extends: cc.Component,

    properties: {
        playerName: cc.Label,
        playerHead: cc.Sprite,
        mail_layer: cc.Node,
        Allhead: cc.SpriteAtlas,
        EXP: cc.ProgressBar,

    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        GameData.gameStart = this;
        // var fun=function () {
        //
        // };
        // this.show(fun);
        this.getHttpdata();
        this.initPepple();
        this.init_exp();

    },
    initPepple() {
        this.playerHead.getComponent(cc.Sprite).spriteFrame = this.Allhead.getSpriteFrame(GameData.head_png);
        this.playerName.string = GameData.playerName;
    },
    /*玩家的经验*/
    init_exp() {
        this.EXP.getComponent("progress_Bar").changeValue(this.exp, this.expAll)
    },

    getHttpdata() {
        let data = startData.people_data;
        GameData.head_png = data.head;
        GameData.playerName = data.name;
        this.exp = data.exp;
        this.expAll = data.expAll;
    },
    show(fun) {
        cc.find("loadbg").getComponent("loadbg").show(fun);
    },
    hide(fun) {
        cc.find("loadbg").getComponent("loadbg").hide(fun);
    },

    testProtobuf: function () {
        var self = this;
        var protoRes = cc.loader.loadRes("proto");

        protobuf.load(protoRes, function (err, root) {
            var request = root.lookup("awesomepackage.Login");
            var message = request.create({id: 1, name: "测试"});
            var buffer = request.encode(message).finish();
            // self.scheduleOnce(function () {
            //    var dec=request.decode(buffer) ;
            //    console.log(dec.name);
            // },1)

        })
    },


    // update (dt) {},
});
